# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 9:17
# @Author  : vvh
# @Email   : 2647167477@qq.com
# @File    : add_good_page.py
# @Software: PyCharm

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from pages.base_pageage import BasePage

class AddGoodPage(BasePage):
    """添加产品页类"""
    # 定位器
    good_name_locator = (By.ID, "name")  # 产品名称
    good_model_locator = (By.ID, "category_id")  # 产品类别
    development_time_locator = (By.ID, 'development_time')  # 研发时间
    blank_locator = (By.CSS_SELECTOR, '#form1 > table > tbody > tr:nth-child(3) > td:nth-child(1)')
    link_url_locator = (By.ID, 'link')  # 详情链接
    development_team_locator = (By.ID, 'development_team')
    cost_price_locator = (By.ID, 'cost_price')  # 成本价
    suggest_price_locator = (By.ID, 'suggested_price')  # 建议零售价
    submit_btn_locator = (By.CSS_SELECTOR, '#form1 > table > tfoot > tr > td > input:nth-child(1)')

    def input_good_name(self, good_name):
        """输入产品名"""
        self.add_good = BasePage(self.driver)
        self.add_good.find(self.good_name_locator).send_keys(good_name)

    def clear_good_name(self):
        """清除输入产品名称"""
        self.add_good.find(self.good_name_locator).clear()

    def select_good_model(self, good_model):
        """在下拉列表选择产品类别"""
        self.model = self.add_good.find(self.good_model_locator)
        Select(self.model).select_by_visible_text(good_model)

    def get_good_model(self):
        """获取产品类别"""
        return Select(self.model).first_selected_option.text

    def clear_development_time(self):
        """清除研发时间"""
        self.add_good.find(self.development_team_locator).clear()

    def input_development_time(self,development_time):
        """输入研发时间"""
        self.add_good = BasePage(self.driver)
        self.add_good.find(self.development_time_locator).send_keys(development_time)
        self.add_good.find(self.blank_locator).click()

    def inout_link_url(self,link_url):
        """输入详情链接"""
        self.add_good.find(self.link_url_locator).clear()
        self.add_good.find(self.link_url_locator).send_keys(link_url)

    def input_development_team(self,development_team):
        """输入开发团队"""
        self.add_good.find(self.development_team_locator).send_keys(development_team)

    def input_cost_price(self,cost_price):
        """输入成本价"""
        self.add_good.find(self.cost_price_locator).send_keys(cost_price)

    def input_suggest_price(self,suggest_price):
        """输入建议售价"""
        self.add_good.find(self.suggest_price_locator).send_keys(suggest_price)

    def submit_good(self):
        """点击保存提交"""
        self.add_good.find(self.submit_btn_locator).click()

    def get_current_url(self):
        """获取添加产品页url"""
        return self.driver.current_url